package com.gp.pj.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.gp.pj.entity.Role;
import com.gp.pj.mapper.RoleMapper;
import com.gp.pj.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gp.pj.vo.RoleVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Chloe
 * @since 2020-12-07
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Resource
    RoleMapper roleMapper;

    @Override
    public JSONArray roleList() {
        List<RoleVo> roleList = roleMapper.roleList();
        JSONArray data = new JSONArray();
        roleList.forEach(item -> {
            if(item.getMenu()!=null){
                String[] menuList = item.getMenu().split(",");
                JSONArray menus = new JSONArray();
                for (String menu :menuList) {
                    menus.add(menu);
                }
                item.setMenus(menus);
            }else{
                JSONArray menus = new JSONArray();
                item.setMenus(menus);
            }
            data.add(item);
        });
        return data;
    }
}
